import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm } from 'naive-ui'
import { {{ bigName }}Model } from '@/api/model/{{ fileName }}-model'

type Props = {
  handleEdit{{ bigName }}: (row: {{ bigName }}Model) => void
  fetchDel{{ bigName }}: (id: number) => void
}

export const use{{ bigName }}ProTable = ({ handleEdit{{ bigName }}, fetchDel{{ bigName }} }: Props) => {
  const columns: ProTableColumn<{{ bigName }}Model>[] = [
    {
      title: '普通列',
      key: 'key1'
    },
    {
      title: '自定义列属性',
      key: 'key2',
      props: {
        style: {
          color: 'red'
        }
      },
      click(row) {
        window['$message'].success(row['key2'])
      }
    },
    {
      type: 'link',
      title: '链接列',
      key: 'key3',
      query: {
        type: 'input'
      },
      click(row) {
        window.open(row['key3'], '_blank')
      }
    },
    {
      type: 'dict',
      title: '字典列',
      key: 'key4',
      dictOptions: [
        {
          value: 100,
          label: '花花',
          props: {
            onclick() {}
          }
        },
        {
          value: 200,
          label: '啦啦'
        }
      ]
    },

    {
      type: 'tag',
      title: '标签列',
      key: 'key5',

      dictOptions: [
        {
          value: 100,
          label: '小明',
          type: 'primary'
        },
        {
          value: 200,
          label: '小红',
          type: 'warning'
        }
      ]
    },
    {
      title: '操作',
      key: 'operation',
      render(row) {
        return (
          <>
            <NButton
              type="primary"
              size="small"
              onClick={() => handleEdit{{ bigName }}(row)}
              quaternary
            >
              修改
            </NButton>
            <NPopconfirm onPositiveClick={() => fetchDel{{ bigName }}(row.id)}>
              \{{
                trigger: () => (
                  <NButton size="small" type="error" quaternary>
                    删除
                  </NButton>
                ),
                default: () => '您确定要删除？'
              }}
            </NPopconfirm>
          </>
        )
      }
    }
  ]

  return {
    columns
  }
}
